package lfm.mpr;

import mail.GmailSender;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;

public class ProgressBarActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.progressbar);
        //El resto del codigo
        ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1);
        new asyncTaskProgressBar().execute();
        //progressBar.setVisibility(View.INVISIBLE);
        
	}//end_onCreate
	
	public class asyncTaskProgressBar extends AsyncTask<Void, Integer, Void> {		 

		ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1);
		
		  @Override
		  protected void onPostExecute(Void result) {
			  progressBar.setVisibility(View.INVISIBLE);
			  Toast.makeText(getApplicationContext(), getString(R.string.newuserok), Toast.LENGTH_LONG).show();
			  Intent intent = new Intent(ProgressBarActivity.this, LfmActivity.class);
	          startActivity(intent);
	            
		  }

		  @Override
		  protected void onPreExecute() {
			  progressBar.setVisibility(View.VISIBLE);
			  Toast.makeText(getApplicationContext(), getString(R.string.newuserok), Toast.LENGTH_LONG).show();
		  }

		  @Override
		  protected void onProgressUpdate(Integer... values) {
		   progressBar.setProgress(values[0]);
		  }

		  @Override
		  protected Void doInBackground(Void... arg0) {

				progressBar.setProgress(5);

				try {
					GmailSender sender = new GmailSender("mpastorroig@gmail.com", "rodies06");
	                sender.sendMail("This is Subject",   
	                        "This is Body",   
	                        "mpastorroig@gmail.com",   
	                        "mpastorroig@gmail.com");
	                
							progressBar.setProgress(100);
							SystemClock.sleep(10000);
						
						} catch (Exception e) {
							//Log.e(logTag, "Hubieron errores al realizar la tarea", e);
							progressBar.setProgress(0);
						} catch (Throwable e) {
							e.printStackTrace();
						}

						return null;}
					}
	
}
